ARG BUILD_IMAGE="golang:alpine"
ARG RUNTIME_IMAGE="alpine:latest"

FROM ${BUILD_IMAGE} AS builder
ARG GOPROXY="https://goproxy.cn,https://goproxy.io,direct"
WORKDIR /app
COPY . /app
RUN GOPROXY=${GOPROXY} GO111MODULE=on CGO_ENABLED=0 GOOS=linux go build -ldflags '-s -w' -o app

FROM ${RUNTIME_IMAGE} AS runner
ARG APP_NAME="app"
COPY --from=builder /app/app /usr/local/bin/${APP_NAME}
RUN ln -s /usr/local/bin/${APP_NAME} /usr/local/bin/entrypoint
ENTRYPOINT [ "entrypoint" ]